﻿@using eLoan.Models;

@model LoanPaymentAddEditModel

@{
    ViewBag.Title = "Payment";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Payment</h2>
        <ol class="breadcrumb">
            <li>
                Funding
            </li>
            <li>
                <a href="@Url.Action("Loans", "Funding")">Loans</a>
            </li>
            <li class="active">
                <strong>Payment</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-8">
            @using (Html.BeginForm("PaymentSave", "Loan", FormMethod.Post, new { id = "saveForm" }))
            {
                
            @Html.AntiForgeryToken()
                
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <table class="table table-bordered table-striped">
                        <tr>
                            <th>@Html.LabelFor(m => m.LoanPayment.DocumentNo)</th>
                            <td>
                                @Html.DisplayFor(m => m.LoanPayment.DocumentNo)
                                @Html.HiddenFor(m => m.LoanPayment.DocumentNo)
                                @Html.HiddenFor(m => m.DBCommand)
                                @Html.HiddenFor(m => m.LoanPayment.StatusID)
                                @if (Model.DBCommand == "Edit")
                                { @Html.HiddenFor(m => m.LoanPayment.ID) }
                            </td>
                        </tr>
                        <tr>
                            <th>@Html.LabelFor(m => Model.LoanPayment.PaymentDate)</th>
                            <td>
                                <div class="form-group" id="pd">
                                    <div class="input-group date">
                                        <span class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </span>
                                        @Html.TextBoxFor(m => m.LoanPayment.PaymentDate, "{0:MM/dd/yyyy}", new { @id = "txtPaymentDate", @class = "form-control" })
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th>@Html.LabelFor(m => m.LoanPayment.PaymentTypeID)</th>
                            <td>
                                @Html.DropDownListFor(m => m.LoanPayment.PaymentTypeID, Model.PaymentTypes, new { @class = "single-line" })
                            </td>
                        </tr>
                        <tr>
                            <th>@Html.LabelFor(m => m.LoanPayment.Amount)</th>
                            <td>
                                @Html.TextBoxFor(m => m.LoanPayment.Amount, "{0:#,###,##0.00}", new { @class = "single-line", @onchange = "FormatMe(this);" })
                            </td>
                        </tr>
                        <tr>
                            <th>@Html.LabelFor(m => m.LoanPayment.Penalty)</th>
                            <td>
                                @Html.TextBoxFor(m => m.LoanPayment.Penalty, "{0:#,###,##0.00}", new { @class = "single-line", @onchange = "FormatMe(this);" })
                            </td>
                        </tr>
                        <tr>
                            <th>@Html.LabelFor(m => m.LoanPayment.Remarks)</th>
                            <td>
                                @Html.TextBoxFor(m => m.LoanPayment.Remarks, new { @class = "single-line" })
                            </td>
                        </tr>
                    </table>

                    <button type="submit" id="btnSave" class="btn btn-primary" name="command" value=@Model.DBCommand>Save</button>
                    <button type="submit" id="btnCancel" class="btn btn-primary cancel" name="command" value="Cancel">Cancel</button>

                </div>
            </div>
            }
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    @Styles.Render("~/plugins/dataPickerStyles")
   
<style>
    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
        margin-top: 5px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .table-search {
        width: 100%;
        border: none;
    }

        .table-search tr {
            margin-top: 0px;
            margin-bottom: 0px;
            padding-top:0px;
            padding-bottom:0px;
            vertical-align: bottom;
        }

        .table-search td {
            margin-left: 10px;
            margin-right: 10px;
            padding-left: 10px;
            padding-right: 10px;
            padding-top: 5px;
            padding-bottom: 5px;
            vertical-align: bottom;
        }

    .table-search td .btnSearch {
        margin-bottom: 0px;
    }

    .table-search td span {
        margin-left: 5px;
    }

    .scrollable {
        height: 350px;
        overflow-y: scroll;
        border: solid 1px #EBEBEB;
    }
</style>

}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/plugins/dataPicker")

    <script type="text/javascript">

        $(document).ready(function () {

            $('#pd .input-group.date').datepicker({
                todayBtn: "linked",
                keyboardNavigation: false,
                forceParse: false,
                calendarWeeks: true,
                format: 'mm/dd/yyyy',
                autoclose: true

            });

            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    return false;
                }
            });

        });

        function FormatMe(me) {
            var val = $(me).val().replace(',', '').replace(',', '').replace(',', '');

            if (isNaN(parseFloat(val)))
                val = 0.00;

            var decimalFormat = parseFloat(val).toFixed(2);
            var commaFormat = FormatNumber(decimalFormat);

            $(me).val(commaFormat);
        }

        function FormatNumber(nStr) {
            nStr += '';
            var x = nStr.split('.');
            var x1 = x[0];
            var x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }

    </script>

}
